/*******************************************************************************
 * This file is part of blueprint4j www.blueprint4j.org.
 * 
 *     blueprint4j is free software: you can redistribute it and/or modify
 *     it under the terms of the GNU Lesser General Public License as published by
 *     the Free Software Foundation, either version 3 of the License, or
 *     (at your option) any later version.
 * 
 *     blueprint4j is distributed in the hope that it will be useful,
 *     but WITHOUT ANY WARRANTY; without even the implied warranty of
 *     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *     GNU Lesser General Public License for more details.
 * 
 *     You should have received a copy of the GNU Lesser General Public License
 *     along with blueprint4j. If not, see <http://www.gnu.org/licenses/>.
 ******************************************************************************/
/**
* $Log: MessageISOField8583.java,v $
* Revision 1.1.1.1  2004/04/22 12:56:14  travisb
* Fir
*
* Revision 1.1.1.1  2003/12/21 09:04:08  jaspervdb
* no message
*
* Revision 1.1.1.1  2003/10/20 15:30:48  travisb
* First import into CVS at Cellstop
*
* Revision 1.1.1.1  2003/03/30 15:25:28  tbulford
* no message
*
* Revision 1.1  2003/01/12 08:30:34  travis
* Import x MANY
*
* Revision 1.1.1.1  2002/12/16 22:14:01  jasper
* no message
*
* Revision 1.3  2002/03/08 15:06:42  travisb
* Tunnel added
*
* Revision 1.2  2002/02/27 09:18:36  travisb
* Changed the way that Protocols are handled they are now passed down from Comms Server to Comms and are forced into play from there.
*
* Revision 1.1  2002/02/20 13:30:43  JasperV
* First time add to new Applications layer
*
* Revision 1.1  2002/01/24 14:18:14  travisb
* First Version of the Application Layer
*
*/

package blueprint4j.messages;

import java.io.*;
import java.util.*;
import java.text.*;

public class MessageISOField8583 extends MessageISOField {

	public MessageISOField8583()
	throws ExceptionMessage {
		super();
		configure8583();
	}

	protected void configure8583() throws ExceptionMessage {
		// Build the standard ISO Fields
		fields[0] = new FieldB(Field.LENGTH_FIXED, 8, 0, "Bit Map");
		fields[1] = new FieldB(Field.LENGTH_FIXED, 8, 1, "Bit Map Extended");
		fields[2] = new FieldN(Field.LENGTH_LLVAR, 19, 2, "Primary account number (PAN)");
		fields[3] = new FieldAN(Field.LENGTH_FIXED, 6, 3, "Precessing code");
		fields[4] = new FieldN(Field.LENGTH_FIXED, 12, 4, "Amount, transaction");
		fields[5] = new FieldN(Field.LENGTH_FIXED, 12, 5, "Amount, Settlement");
		fields[6] = new FieldN(Field.LENGTH_FIXED, 12, 6, "Amount, cardholder billing");
		fields[7] = new FieldN(Field.LENGTH_FIXED, 10, 7, "Transmission date & time");
		fields[8] = new FieldN(Field.LENGTH_FIXED, 8, 8, "Amount, Cardholder billing fee");
		fields[9] = new FieldN(Field.LENGTH_FIXED, 8, 9, "Conversion rate, Settlement");
		fields[10] = new FieldN(Field.LENGTH_FIXED, 8, 10, "Conversion rate, cardholder billing");
		fields[11] = new FieldN(Field.LENGTH_FIXED, 6, 11, "Systems trace audit number");
		fields[12] = new FieldN(Field.LENGTH_FIXED, 6, 12, "Time, Local transaction");
		fields[13] = new FieldN(Field.LENGTH_FIXED, 4, 13, "Date, Local transaction");
		fields[14] = new FieldN(Field.LENGTH_FIXED, 4, 14, "Date, Expiration");
		fields[15] = new FieldN(Field.LENGTH_FIXED, 4, 15, "Date, Settlement");
		fields[16] = new FieldN(Field.LENGTH_FIXED, 4, 16, "Date, conversion");
		fields[17] = new FieldN(Field.LENGTH_FIXED, 4, 17, "Date, capture");
		fields[18] = new FieldN(Field.LENGTH_FIXED, 4, 18, "Merchant type");
		fields[19] = new FieldN(Field.LENGTH_FIXED, 3, 19, "Acquiring institution country code");
		fields[20] = new FieldN(Field.LENGTH_FIXED, 3, 20, "PAN Extended, country code");
		fields[21] = new FieldN(Field.LENGTH_FIXED, 3, 21, "Forwarding institution. country code");
		fields[22] = new FieldN(Field.LENGTH_FIXED, 3, 22, "Point of service entry mode");
		fields[23] = new FieldN(Field.LENGTH_FIXED, 3, 23, "Application PAN number");
		fields[24] = new FieldN(Field.LENGTH_FIXED, 3, 24, "Network International identifier");
		fields[25] = new FieldN(Field.LENGTH_FIXED, 2, 25, "Point of service condition code");
		fields[26] = new FieldN(Field.LENGTH_FIXED, 2, 26, "Point of service capture code");
		fields[27] = new FieldN(Field.LENGTH_FIXED, 1, 27, "Authorising identification response length");
		fields[28] = new FieldAN(Field.LENGTH_FIXED, 9, 28, "Amount, transaction fee");
		fields[29] = new FieldAN(Field.LENGTH_FIXED, 9, 29, "Amount. settlement fee");
		fields[30] = new FieldAN(Field.LENGTH_FIXED, 9, 30, "Amount, transaction processing fee");
		fields[31] = new FieldAN(Field.LENGTH_FIXED, 9, 31, "Amount, settlement processing fee");
		fields[32] = new FieldN(Field.LENGTH_LLVAR, 11, 32, "Acquiring institution identification code");
		fields[33] = new FieldN(Field.LENGTH_LLVAR, 11, 33, "Forwarding institution identofication code");
		fields[34] = new FieldN(Field.LENGTH_LLVAR, 28, 34, "Primary account number, extended");
		fields[35] = new FieldANS(Field.LENGTH_LLVAR, 37, 35, "Track 2 data");
		fields[36] = new FieldN(Field.LENGTH_LLLVAR, 104, 36, "Track 3 data");
		fields[37] = new FieldAN(Field.LENGTH_FIXED, 12, 37, "Retrieval reference number");
		fields[38] = new FieldAN(Field.LENGTH_FIXED, 6, 38, "Authorisation identification response");
		fields[39] = new FieldAN(Field.LENGTH_FIXED, 2, 39, "Response code");
		fields[40] = new FieldAN(Field.LENGTH_FIXED, 3, 40, "Service restriction code");
		fields[41] = new FieldANS(Field.LENGTH_FIXED, 8, 41, "Card acceptor terminal identification");
		fields[42] = new FieldANS(Field.LENGTH_FIXED, 15, 42, "Card acceptor identification code");
		fields[43] = new FieldANS(Field.LENGTH_FIXED, 40, 43, "Card acceptor name/location");
		fields[44] = new FieldAN(Field.LENGTH_LLVAR, 25, 44, "Additional response data");
		fields[45] = new FieldAN(Field.LENGTH_LLVAR, 76, 45, "Track 1 Data");
		fields[46] = new FieldAN(Field.LENGTH_LLLVAR, 999, 46, "Additional data - ISO");
		fields[47] = new FieldAN(Field.LENGTH_LLLVAR, 999, 47, "Additional data - National");
		fields[48] = new FieldAN(Field.LENGTH_LLLVAR, 999, 48, "Additional data - Private");
		fields[49] = new FieldN(Field.LENGTH_FIXED, 3, 49, "Currency code, transaction");
		fields[50] = new FieldAN(Field.LENGTH_FIXED, 3, 50, "Currency code, settlement");
		fields[51] = new FieldN(Field.LENGTH_FIXED, 3, 51, "Currency code, cardholder billing");
		fields[52] = new FieldB(Field.LENGTH_FIXED, 8, 52, "Personal Identification number data");
		fields[53] = new FieldN(Field.LENGTH_FIXED, 18, 53, "Security related control information");
		fields[54] = new FieldAN(Field.LENGTH_LLLVAR, 120, 54, "Additional amounts");
		fields[55] = new FieldANS(Field.LENGTH_LLLVAR, 999, 55, "Reserved ISO");
		fields[56] = new FieldANS(Field.LENGTH_LLLVAR, 999, 56, "Reserved ISO");
		fields[57] = new FieldANS(Field.LENGTH_LLLVAR, 999, 57, "Reserved National");
		fields[58] = new FieldANS(Field.LENGTH_LLLVAR, 999, 58, "Reserved National");
		fields[59] = new FieldANS(Field.LENGTH_LLLVAR, 999, 59, "Reserved for national use");
		fields[60] = new FieldAN(Field.LENGTH_LVAR, 7, 60, "Advice/reason code (private reserved)");
		fields[61] = new FieldANS(Field.LENGTH_LLLVAR, 999, 61, "Reserved Private");
		fields[62] = new FieldANS(Field.LENGTH_LLLVAR, 999, 62, "Reserved Private");
		fields[63] = new FieldANS(Field.LENGTH_LLLVAR, 999, 63, "Reserved Private");
		fields[64] = new FieldB(Field.LENGTH_FIXED, 8, 64, "Message authentication code (MAC)");
		fields[65] = new FieldB(Field.LENGTH_FIXED, 8, 65, "Bit map, tertiary");
		fields[66] = new FieldN(Field.LENGTH_FIXED, 1, 66, "Settlement code");
		fields[67] = new FieldN(Field.LENGTH_FIXED, 2, 67, "Extended payment code");
		fields[68] = new FieldN(Field.LENGTH_FIXED, 3, 68, "Receiving institution country code");
		fields[69] = new FieldN(Field.LENGTH_FIXED, 3, 69, "Settlement institution county code");
		fields[70] = new FieldN(Field.LENGTH_FIXED, 3, 70, "Network management Information code");
		fields[71] = new FieldN(Field.LENGTH_FIXED, 4, 71, "Message number");
		fields[72] = new FieldN(Field.LENGTH_FIXED, 4, 72, "Message number, last");
		fields[73] = new FieldN(Field.LENGTH_FIXED, 6, 73, "Date, Action");
		fields[74] = new FieldN(Field.LENGTH_FIXED, 10, 74, "Credits, number");
		fields[75] = new FieldN(Field.LENGTH_FIXED, 10, 75, "Credits, reversal number");
		fields[76] = new FieldN(Field.LENGTH_FIXED, 10, 76, "Debits, number");
		fields[77] = new FieldN(Field.LENGTH_FIXED, 10, 77, "Debits, reversal number");
		fields[78] = new FieldN(Field.LENGTH_FIXED, 10, 78, "Transfer number");
		fields[79] = new FieldN(Field.LENGTH_FIXED, 10, 79, "Transfer, reversal number");
		fields[80] = new FieldN(Field.LENGTH_FIXED, 10, 80, "Inquiries number");
		fields[81] = new FieldN(Field.LENGTH_FIXED, 10, 81, "Authorisations, number");
		fields[82] = new FieldN(Field.LENGTH_FIXED, 12, 82, "Credits, processsing fee amount");
		fields[83] = new FieldN(Field.LENGTH_FIXED, 12, 83, "Credits, transaction fee amount");
		fields[84] = new FieldN(Field.LENGTH_FIXED, 12, 84, "Debits, processing fee amount");
		fields[85] = new FieldN(Field.LENGTH_FIXED, 12, 85, "Debits, transaction fee amount");
		fields[86] = new FieldN(Field.LENGTH_FIXED, 15, 86, "Credits, amount");
		fields[87] = new FieldN(Field.LENGTH_FIXED, 15, 87, "Credits, reversal amount");
		fields[88] = new FieldN(Field.LENGTH_FIXED, 15, 88, "Debits, amount");
		fields[89] = new FieldN(Field.LENGTH_FIXED, 15, 89, "Debits, reversal amount");
		fields[90] = new FieldN(Field.LENGTH_FIXED, 42, 90, "Original data elements");
		fields[91] = new FieldAN(Field.LENGTH_FIXED, 1, 91, "File update code");
		fields[92] = new FieldN(Field.LENGTH_FIXED, 2, 92, "File security code");
		fields[93] = new FieldN(Field.LENGTH_FIXED, 5, 93, "Response indicator");
		fields[94] = new FieldAN(Field.LENGTH_FIXED, 7, 94, "Service indicator");
		fields[95] = new FieldAN(Field.LENGTH_FIXED, 42, 95, "Replacement amounts");
		fields[96] = new FieldAN(Field.LENGTH_FIXED, 8, 96, "Message security code");
		fields[97] = new FieldN(Field.LENGTH_FIXED, 16, 97, "Amount, net settlement");
		fields[98] = new FieldANS(Field.LENGTH_FIXED, 25, 98, "Payee");
		fields[99] = new FieldN(Field.LENGTH_LLVAR, 11, 99, "Settlement institution identification code");
		fields[100] = new FieldN(Field.LENGTH_LLVAR, 11, 100, "Receiving institution identification code");
		fields[101] = new FieldANS(Field.LENGTH_FIXED, 17, 101, "File name");
		fields[102] = new FieldANS(Field.LENGTH_LLVAR, 28, 102, "Account identification 1");
		fields[103] = new FieldANS(Field.LENGTH_LLVAR, 28, 103, "Account identification 2");
		fields[104] = new FieldANS(Field.LENGTH_LLVAR, 100, 104, "Transaction description");
		fields[105] = new FieldANS(Field.LENGTH_LLLVAR, 999, 105, "Reserved for ISO use");
		fields[106] = new FieldANS(Field.LENGTH_LLLVAR, 999, 106, "Reserved for ISO use");
		fields[107] = new FieldANS(Field.LENGTH_LLLVAR, 999, 107, "Reserved for ISO use");
		fields[108] = new FieldANS(Field.LENGTH_LLLVAR, 999, 108, "Reserved for ISO use");
		fields[109] = new FieldANS(Field.LENGTH_LLLVAR, 999, 109, "Reserved for ISO use");
		fields[110] = new FieldANS(Field.LENGTH_LLLVAR, 999, 110, "Reserved for ISO use");
		fields[111] = new FieldANS(Field.LENGTH_LLLVAR, 999, 111, "Reserved for ISO use");
		fields[112] = new FieldANS(Field.LENGTH_LLLVAR, 999, 112, "Reserved for national use");
		fields[113] = new FieldN(Field.LENGTH_LLVAR, 11, 113, "Authorising agent institution id code");
		fields[114] = new FieldANS(Field.LENGTH_LLLVAR, 999, 114, "Reserved for national use");
		fields[115] = new FieldANS(Field.LENGTH_LLLVAR, 999, 115, "Reserved for national use");
		fields[116] = new FieldANS(Field.LENGTH_LLLVAR, 999, 116, "Reserved for national use");
		fields[117] = new FieldANS(Field.LENGTH_LLLVAR, 999, 117, "Reserved for national use");
		fields[118] = new FieldANS(Field.LENGTH_LLLVAR, 999, 118, "Reserved for national use");
		fields[119] = new FieldANS(Field.LENGTH_LLLVAR, 999, 119, "Reserved for national use");
		fields[120] = new FieldANS(Field.LENGTH_LLLVAR, 999, 120, "Reserved for private use");
		fields[121] = new FieldANS(Field.LENGTH_LLLVAR, 999, 121, "Reserved for private use");
		fields[122] = new FieldANS(Field.LENGTH_LLLVAR, 999, 122, "Reserved for private use");
		fields[123] = new FieldANS(Field.LENGTH_LLLVAR, 999, 123, "Reserved for private use");
		fields[124] = new FieldANS(Field.LENGTH_LLLVAR, 255, 124, "Info Text");
		fields[125] = new FieldANS(Field.LENGTH_LLLVAR, 50, 125, "Network management information");
		fields[126] = new FieldANS(Field.LENGTH_LLLVAR, 6, 126, "Issuer trace id");
		fields[127] = new FieldANS(Field.LENGTH_LLLVAR, 999, 127, "Reserved for private use");
		fields[128] = new FieldB(Field.LENGTH_FIXED, 8, 128, "Message Authentication code");

		// Create needed fields message type allowed to be anything we like
		fields[129] = message_type = new FieldN( Field.LENGTH_FIXED, 4 , -1, "Type" );
	}


	/**
	* Sets the iso message type
	* @param message_type takes a hex value for the tywe of message
	* therfore 0800 - 0x0800
	*/
	public void setType( int p_message_type )
	throws ExceptionMessage {
		message_type.set( Utils.convertLongToHex( p_message_type ) );
		date_last_modified = new Date();
	}


	/**
	* Gets the iso type as a hex value
	* @param message_type takes a hex value for the type of message
	* therfore 0800 - 0x0800
	*/
	public int getTypeInt()
	throws ExceptionMessage {
		try {
			return (int)Utils.convertHexToLong(getType());
		} catch (NumberFormatException nfe) {}
		throw new ExceptionMessage("Type recieved is not hex, but using 8583 message format");
	}
}

